﻿using AutoMapper;
using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.MenuCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.MenuHandler
{
    public class QueryPidHandler : IRequestHandler<QueryPidCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Menu> menuRep;
        private readonly IMapper mapper;

        public QueryPidHandler(IBaseRepository<Menu> menuRep,IMapper mapper)
        {
            this.menuRep = menuRep;
            this.mapper = mapper;
        }
        public Task<APIResult<int>> Handle(QueryPidCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var entity = menuRep.GetAll().Where(x=>x.PId==request.MenuId);
            if (entity.Count()>0)
            {
                result.Code = APIEnum.Success;
                result.Msg = "查询成功";
                result.Data=1;
            }
            else
            {
                result.Code=APIEnum.Failed;
                result.Msg = "查询失败";
                result.Data = 0;
                
            }
           
            return Task.FromResult(result);
        }
    }
}
